public class Solution206 {
    /**
     * 反转一个单链表。
     */

    // 迭代
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        while (head!=null){
            ListNode temp = head.next;
            head.next = pre;
            pre = head;
            head = temp;
        }
        return pre;
    }

    // 递归
    public ListNode reverseList2(ListNode head){
        if (head == null || head.next == null) return head;
        ListNode temp = reverseList2(head.next);
        head.next.next = head;
        head.next = null;
        return temp;
    }
}
